home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Visual Database / Visual BASIC 5.0 (Ent. Edition) / Vb5ent Extractor.EXE / VB / SAMPLES / ENTRPRIS / APE / AECLIENT / CLSQUETL.CLS < prev    next >
Encoding:
Visual Basic class definition  |  1996-12-23  |  14.4 KB  |  312 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "clsQueueTestTool"
  6. Attribute VB_GlobalNameSpace = False
  7. Attribute VB_Creatable = False
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = False
  10. Option Explicit
  11. '-------------------------------------------------------------------------
  12. 'This class provides a RunTest method to be called to run a Queue Manager
  13. 'model test
  14. '-------------------------------------------------------------------------
  15. Private WithEvents moEventReturn As AEExpediter.EventReturn  'Expediter may raise an event
  16. Attribute moEventReturn.VB_VarHelpID = -1
  17.                                                              'to return results
  18.  
  19. Public Sub RunTest()
  20.     '-------------------------------------------------------------------------
  21.     'Purpose:   Executes a loop for glNumberOfCalls each time calling
  22.     '           AEQueueMgr.Queue.Add.  This method actually runs
  23.     '           a test according to set properties
  24.     'Assumes:   All Client properties have been set.
  25.     'Effects:
  26.     '           Calls CompleteTest when finished calling QueueMgr if no
  27.     '           callbacks are expected
  28.     '           Calls AddServiceRecord procedure after each call to QueueMgr
  29.     '           if callbacks are expected
  30.     '   [gbRunning]
  31.     '           Is true during procedure
  32.     '   [glFirstServiceTick]
  33.     '           becomes the tick count of when the test is started
  34.     '   [glLastCallbackTick]
  35.     '           becomes the tick count of when the last call is made
  36.     '   [glCallsMade]
  37.     '           is incremented every time the QueueMgr is called
  38.     '   [glCallsReturned]
  39.     '           is incremented every time the QueueMgr is called if no
  40.     '           callback is expected
  41.     '-------------------------------------------------------------------------
  42.     Const lMAX_COUNT = 2147483647
  43.     Dim s As String         'Error message to log and display
  44.     Dim lServiceID As Long  'Service Request ID
  45.     Dim lTicks As Long      'Tick Count in milliseconds
  46.     Dim lEndTick As Long    'DoEvents loop until this tick count
  47.     Dim lCallNumber As Long 'Number of calls
  48.     Dim lNumberOfCalls As Long      'Test duration in number of calls
  49.     Dim iDurationMode As Integer    'Test duration mode
  50.     Dim lDurationTicksEnd As Long   'Tick that test should end on
  51.     Dim iRetry As Integer   'Number of call retries made because call rejection
  52.     Dim bPostingServices As Boolean 'If true, in main loop of procedure
  53.     Dim vSendData As Variant        'Data to send with Service Request
  54.     Dim bRandomSendData As Boolean  'If true vSendData needs generated before each new request
  55.     Dim sSendCommand As String      'Command string to be sent with Service Request
  56.     Dim bRandomCommand As Boolean   'If true sSendCommand needs generated before each new request
  57.     Dim lCallWait As Long           'Number of ticks to wait between calls
  58.     Dim bRandomWait As Boolean      'If true lCallWait needs generated before each new request
  59.     Dim bSendSomething As Boolean    'If true data needs passed with request
  60.     Dim bReceiveSomething As Boolean 'If true something is expeted back
  61.     Dim oCallback As clsCallback    'Callback object to pass with requests
  62.     Dim bLog As Boolean             'If true log records
  63.     Dim bShow As Boolean            'If true update display
  64.     Dim iCallbackMode As Integer    'Determines if and how results are returned from QueueMgr
  65.     Dim oQueue As AEQueueMgr.Queue  'Queue object to post service requests to
  66.  
  67.     On Error GoTo RunTestError
  68.     
  69.     'If there is reentry by a timer click exit sub
  70.     If gbRunning Then Exit Sub
  71.     gbRunning = True
  72.     
  73.     'Set the local variables to direct the testing
  74.     Set oQueue = New AEQueueMgr.Queue
  75.     Set oCallback = New clsCallback
  76.     bRandomSendData = GetTestData(bSendSomething, bReceiveSomething, vSendData)
  77.     lCallWait = GetValueFromRange(gudtWaitPeriod, bRandomWait)
  78.     sSendCommand = GetServiceCommand(bRandomCommand)
  79.     bLog = gbLog
  80.     bShow = gbShow
  81.     iCallbackMode = glCallbackMode
  82.     
  83.     'Set the DefaultCallback property if it will be needed
  84.     'Setting the default callback even when the client will be passing
  85.     'a callback every call improves performance by keeping RemAuto and DCOM
  86.     'form tearing down the stub and proxy for the callback object
  87.     'when the expediter's reference count of the callback object is zero
  88.     'Having one reference always on the server side keeps the stub and proxy
  89.     'from being torn done, which removes the need for the stub and proxy to have
  90.     'to be continually recreated during the test
  91.     If iCallbackMode = giUSE_DEFAULT_CALLBACK Or giUSE_PASSED_CALLBACK Then Set oQueue.DefaultCallBack = oCallback
  92.     'Set the withevents object if it will be needed
  93.     If iCallbackMode = giRETURN_BY_SYNC_EVENT Then Set moEventReturn = oQueue.GetEventObject
  94.     
  95.     s = LoadResString(giTEST_STARTED)
  96.     If bLog Then AddLogRecord 0, s, GetTickCount(), False
  97.     DisplayStatus s
  98.     glFirstServiceTick = GetTickCount()
  99.     
  100.     'Test duration variables
  101.     iDurationMode = giTestDurationMode
  102.     If iDurationMode = giTEST_DURATION_CALLS Then
  103.         lNumberOfCalls = glNumberOfCalls
  104.     ElseIf iDurationMode = giTEST_DURATION_TICKS Then
  105.         lDurationTicksEnd = glFirstServiceTick + glTestDurationInTicks
  106.     End If
  107.     
  108.     bPostingServices = True
  109.     Do While Not gbStopping
  110.         'Check if new data needs generated because of randomization
  111.         If bRandomSendData Then bRandomSendData = GetTestData(bSendSomething, bReceiveSomething, vSendData)
  112.         If bRandomWait Then lCallWait = GetValueFromRange(gudtWaitPeriod, bRandomWait)
  113.         If bRandomCommand Then sSendCommand = GetServiceCommand(bRandomCommand)
  114.         
  115.         'Increment number of calls made
  116.         lCallNumber = glCallsMade + 1
  117.         'Queue the Service
  118.         'Post this Service to the queue
  119.         'Queue an asynchronous Service
  120.         iRetry = 0
  121.         lTicks = GetTickCount
  122.         
  123.         'Display CallsMade
  124.         If bShow Then
  125.             With frmClient.lblCallsMade
  126.                 .Caption = lCallNumber
  127.                 .Refresh
  128.             End With
  129.         End If
  130.         
  131.         If bReceiveSomething Then
  132.             'We are expecting a callback.
  133.             Select Case iCallbackMode
  134.                 Case giUSE_DEFAULT_CALLBACK, giRETURN_BY_SYNC_EVENT
  135.                     lServiceID = oQueue.Add(sSendCommand, iCallbackMode, vSendData)
  136.                 Case giUSE_PASSED_CALLBACK
  137.                     lServiceID = oQueue.Add(sSendCommand, iCallbackMode, vSendData, oCallback)
  138.             End Select
  139.             'If lServiceID = 0 then QueueMgr did not process Service request
  140.             'because it was stopped.
  141.             If lServiceID = 0 Then Exit Do
  142.             AddServiceRecord lServiceID, sSendCommand, GetTickCount()
  143.         ElseIf bSendSomething Then
  144.             'Sending data but nothing comming back.
  145.             'Dont receive a callback.
  146.             lServiceID = oQueue.Add(sSendCommand, giNO_CALLBACK, vSendData)
  147.             'Increment the CallsReturned global
  148.             glCallsReturned = glCallsReturned + 1
  149.             If bShow Then
  150.                 With frmClient.lblCallsReturned
  151.                     .Caption = glCallsReturned
  152.                     .Refresh
  153.                 End With
  154.             End If
  155.         Else
  156.             'Just make the call, nothing else.
  157.             lServiceID = oQueue.Add(sSendCommand, giNO_CALLBACK)
  158.             'Increment the CallsReturned global
  159.             glCallsReturned = glCallsReturned + 1
  160.             If bShow Then
  161.                 With frmClient.lblCallsReturned
  162.                     .Caption = glCallsReturned
  163.                     .Refresh
  164.                 End With
  165.             End If
  166.         End If
  167.         If bLog Then AddLogRecord lServiceID, LoadResString(giQUEUE_SERVICE) & gsSEPERATOR & sSendCommand, lTicks, False
  168.         
  169.         'If gbStopping Then Exit Do
  170.         'Go into an idle loop util the next call.
  171.         'Also go into idle loop if difference between
  172.         'calls sent and calls received is greater than giCALL_SENT_AND_RECEIVED_MAX_DIFFERENCE
  173.         If lCallWait > 0 Or (lCallNumber - glCallsReturned) > giCALL_SENT_AND_RECEIVED_MAX_DIFFERENCE Then
  174.             lEndTick = GetTickCount + lCallWait
  175.             Do While ((GetTickCount() < lEndTick) Or ((lCallNumber - glCallsReturned) > giCALL_SENT_AND_RECEIVED_MAX_DIFFERENCE)) And Not gbStopping
  176.                 DoEvents
  177.             Loop
  178.         End If
  179.         glCallsMade = lCallNumber
  180.         
  181.         'See if it is time to stop the test
  182.         If iDurationMode = giTEST_DURATION_CALLS Then
  183.             If lCallNumber >= lNumberOfCalls Then Exit Do
  184.         ElseIf iDurationMode = giTEST_DURATION_TICKS Then
  185.             If GetTickCount >= lDurationTicksEnd Then Exit Do
  186.         End If
  187.     Loop
  188. StopTestNow:
  189.     bPostingServices = False
  190.     glLastCallbackTick = GetTickCount()
  191.     gbRunning = False
  192.     If gbStopping Then
  193.         'Someone hit the stop button on the Explorer.
  194.         gStopTest
  195.         Exit Sub
  196.     End If
  197.     If bLog Then AddLogRecord 0, LoadResString(giSERVICES_POSTED), GetTickCount(), False
  198.     If Not bReceiveSomething Then
  199.         'Not expecting callbacks. The test is done.
  200.         CompleteTest
  201.     End If
  202.     Set oCallback = Nothing
  203.     Set oQueue = Nothing
  204.     Exit Sub
  205. RunTestError:
  206.     Select Case Err.Number
  207.         Case RPC_E_CALL_REJECTED
  208.             'Collision error, the OLE server is busy
  209.             Dim il As Integer
  210.             Dim ir As Integer
  211.             'First check if stopping test
  212.             If gbStopping Then GoTo StopTestNow
  213.             If bLog Then AddLogRecord 0, LoadResString(giQUEUE_SERVICE_COLLISION_RETRY), GetTickCount(), False
  214.             If iRetry < giMAX_ALLOWED_RETRIES Then
  215.                 iRetry = iRetry + 1
  216.                 ir = Int((giRETRY_WAIT_MAX - giRETRY_WAIT_MIN + 1) * Rnd + giRETRY_WAIT_MIN)
  217.                 For il = 0 To ir
  218.                     DoEvents
  219.                 Next il
  220.                 If gbStopping Then Resume Next Else Resume
  221.             Else
  222.                 'We reached our max retries
  223.                 s = LoadResString(giCOLLISION_ERROR)
  224.                 If bLog Then AddLogRecord 0, s, GetTickCount(), False
  225.                 DisplayStatus s
  226.                 StopOnError s
  227.                 Exit Sub
  228.             End If
  229.         Case giQUEUE_MGR_IS_BUSY + vbObjectError
  230.             lEndTick = GetTickCount + lCallWait + giQUEUE_WAIT_RETRY_MIN
  231.             If gbLog Then AddLogRecord lServiceID, Err.Description, GetTickCount, False
  232.             Do While GetTickCount() < lEndTick And Not gbStopping
  233.                 DoEvents
  234.             Loop
  235.             Resume
  236.         Case ERR_OBJECT_VARIABLE_NOT_SET
  237.             'QueueMgr was not successfully created
  238.             'stop client
  239.             'If gbStopping is true the error occurred
  240.             'because StopOnError was already called when
  241.             'handling a callback
  242.             If Not gbStopping Then
  243.                 s = LoadResString(giQUEUE_SERVICE_ERROR) & CStr(Err.Number) & gsSEPERATOR & Err.Source & gsSEPERATOR & Err.Description
  244.                 DisplayStatus Err.Description
  245.                 If gbLog Then AddLogRecord 0, s, GetTickCount(), False
  246.                 StopOnError s
  247.             End If
  248.             Exit Sub
  249.         Case ERR_CANT_FIND_KEY_IN_REGISTRY
  250.             'AEInstancer.Instancer is a work around for error
  251.             '-2147221166 which occurrs every time a client
  252.             'object creates an instance of a remote server,
  253.             'destroys it, registers it local, and tries to
  254.             'create a local instance.  The client can not
  255.             'create an object registered locally after it created
  256.             'an instance while it was registered remotely
  257.             'until it shuts down and restarts.  Therefore,
  258.             'it works to call another process to create the
  259.             'local instance and pass it back.
  260.             Dim oInstancer As AEInstancer.Instancer
  261.             Set oInstancer = New AEInstancer.Instancer
  262.             Set oQueue = oInstancer.object("AEQueueMgr.Queue")
  263.             Set oInstancer = Nothing
  264.             Resume Next
  265.         Case RPC_S_UNKNOWN_AUTHN_TYPE
  266.             'Tried to connect to a server that does not support
  267.             'specified authentication level.  Display message and
  268.             'switch to no authentication and try again
  269.             Dim iResult As Integer
  270.             s = LoadResString(giUSING_NO_AUTHENTICATION)
  271.             DisplayStatus s
  272.             AddLogRecord 0, s, 0, False
  273.             glConnectionAuthentication = RPC_C_AUTHN_LEVEL_NONE
  274.             iResult = goRegClass.SetAutoServerSettings(True, "AEQueueMgr.Queue", , gsConnectionAddress, gsConnectionProtocol, glConnectionAuthentication)
  275.             Resume
  276.         Case ERR_OVER_FLOW
  277.             s = CStr(Err.Number) & gsSEPERATOR & Err.Source & gsSEPERATOR & Err.Description
  278.             If lCallNumber = glMAX_LONG Then lCallNumber = 0
  279.             If glCallsReturned = glMAX_LONG Then glCallsReturned = 0
  280.             DisplayStatus Err.Description
  281.             If gbLog Then AddLogRecord 0, s, GetTickCount(), False
  282.         Case Else
  283.             s = LoadResString(giQUEUE_SERVICE_ERROR) & CStr(Err.Number) & gsSEPERATOR & Err.Source & gsSEPERATOR & Err.Description
  284.             DisplayStatus Err.Description
  285.             If gbLog Then AddLogRecord 0, s, GetTickCount(), False
  286.             If bPostingServices Then
  287.                 StopOnError s
  288.                 Exit Sub
  289.             Else
  290.                 Resume Next
  291.             End If
  292.     End Select
  293. End Sub
  294.  
  295. Private Sub moEventReturn_ServiceResult(ByVal lServiceID As Long, ByVal vServiceReturn As Variant, ByVal sServiceError As String)
  296.     '-------------------------------------------------------------------------
  297.     'Purpose:   Event raised by Expediter class object to return results
  298.     'IN:
  299.     '   [lServiceID]
  300.     '           Service Request ID
  301.     '   [vServiceReturn]
  302.     '           Data returned by Service Request
  303.     '   [sServiceError]
  304.     '           Error information for errors that occured processing Service Request.
  305.     '           Information is delimited by a semi-colon and a space in the following
  306.     '           format:  "number; source; description"
  307.     'Effects:
  308.     '   Calls CallbackHandler procedure
  309.     '-------------------------------------------------------------------------
  310.     CallBackHandler lServiceID, vServiceReturn, sServiceError
  311. End Sub
  312.